package com.hyfrogx.modules.manage.controller.course;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.app.entity.User;
import com.hyfrogx.modules.manage.controller.BaseController;
import com.hyfrogx.modules.manage.entity.course.CourseManageEntity;
import com.hyfrogx.modules.manage.entity.course.CourseManageRemarkEntity;
import com.hyfrogx.modules.manage.service.course.CourseManageRemarkService;
import com.hyfrogx.modules.manage.service.course.CourseManageSectionService;
import com.hyfrogx.modules.manage.service.course.CourseManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
 * @author 罗春杰-技术部
 */
@RestController
@RequestMapping("api/share/section")
@Api(value = "CourseShareSectionController",tags = {"后台-分享课程控制类"})
public class CourseShareSectionController extends BaseController {

    @Autowired
    CourseManageSectionService sectionService;

    @Autowired
    CourseManageService ManageService;

    @Autowired
    CourseManageRemarkService remarkService;

    /**
     * 获取课程详情
     * @param
     * @return HyCourseManage
     * @throws Exception
     */
    @RequestMapping(value = "listCourseManageSynopsis", method = RequestMethod.POST)
    @ApiOperation("获取课程详情")
    public R ListCourseManageSynopsis( Integer id) {
        try {
            List<CourseManageRemarkEntity> remark = remarkService.ListGetTenRemark(id);
            CourseManageEntity manageEntity = ManageService.getById(id);
            manageEntity.setRemark(remark);
            return R.ok().put("data",manageEntity);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }


    /**
     * 查看上架的章节
     * @return
     */
    @RequestMapping(value = "/courseDetails", method = RequestMethod.POST)
    @ApiOperation("查看上架的章节")
    public R CourseDetails(@RequestBody Map map) {
        try {
            Page page = sectionService.getAllisPutawaySection(new QueryExt(map));
            if (page != null) {
                return R.ok().put("data",page);
            } else {
                return R.error("暂无章节");
            }
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }
}
